
import {
  ChatConversationsResponse,
  ChatMessagesResponse,
  ChatResponse,
  GetConversationMessagesParams,
  GetConversationsParams,
  SendMessageParams
} from 'types/chat';
import { CHAT_API_TOKEN } from 'constant';
import { request } from 'utils/request';
import type { ApiResponse } from 'types/common';
import { DIFY_API_URL } from 'constant';

export const chatApi = {
  // 发送对话消息
  sendMessage: (data: SendMessageParams) =>
    request.post<any, ChatResponse>(`${DIFY_API_URL}/chat-messages`, {
      data,
      headers: {
        'Content-Type': 'application/json',
        Authorization: CHAT_API_TOKEN,
      },
    }),

  // 获取会话列表
  getConversations: (params: GetConversationsParams) =>
    request.get<any, ChatConversationsResponse>(`${DIFY_API_URL}/conversations`, {
      params,
      headers: {
        'Content-Type': 'application/json',
        Authorization: CHAT_API_TOKEN,
      }
    }),

  // 获取会话具体消息
  getConversationMessages: (params: GetConversationMessagesParams) =>
    request.get<any, ChatMessagesResponse>(`${DIFY_API_URL}/messages`, {
      params,
      headers: {
        'Content-Type': 'application/json',
        Authorization: CHAT_API_TOKEN,
      }
    }),

  // 删除会话
  deleteConversation: (conversation_id: string, user: string) =>
    request.delete<ApiResponse<void>>(`${DIFY_API_URL}/conversations/${conversation_id}`, {
      data: { user },
      headers: {
        'Content-Type': 'application/json',
        Authorization: CHAT_API_TOKEN,
      }
    }),
};